class TipManager {
  private static _instance: TipManager;
  private container: egret.DisplayObjectContainer;
  private eventDispatcher: egret.EventDispatcher;
  private _tipsPool = new Pool.ObjectPool(ToolTips);
  constructor() {
    Logger.assert(!TipManager._instance, "Create tip manager multiple times");
  }

  public static get instance(): TipManager {
    if (!TipManager._instance) {
      TipManager._instance = new TipManager();
    }
    return TipManager._instance;
  }

  init(container: egret.DisplayObjectContainer): boolean {
    this.container = container;
    this._tipsPool = new Pool.ObjectPool(ToolTips);
    return true;
  }

  show(message: string) {
    if (!this.container) {
      return;
    }
    let _tips = this._tipsPool.get();
    _tips.refreshView(message);
    this.container.addChild(_tips);
    egret.Tween.removeTweens(_tips);
    _tips.y = GameUtils.getSceneHeigth() / 4;
    _tips.x = 0;
    _tips.alpha = 1;
    _tips.visible = true;

    let _tween = egret.Tween.get(_tips);
    _tween.wait(2000).to({ y: GameUtils.getSceneHeigth() / 5, alpha: 0 }, 500).call(() => {
      // egret.Tween.removeTweens(_tips);
      // this.container.removeChild(_tips)
      _tips.visible = false;
      this._tipsPool.dispose(_tips);
    });
  }

  removeAllTips() {
    this.container.removeChildren();
    this._tipsPool = null;
  }
}